//
//  WeiboFrameModel.m
//  SinaWeibo
//
//  Created by Apple on 16/8/18.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "WeiboFrameModel.h"
#import "StatuesModel.h"
#import "UserModel.h"

#define kMargin 10
#define kUserImageWidth 40


@implementation WeiboFrameModel

-(void)setStatuesModel:(StatuesModel *)StatuesModel{
    
    _StatuesModel = StatuesModel;
    
    //1.计算头像的值
    _userImageFrame = CGRectMake(kMargin, kMargin, kUserImageWidth, kUserImageWidth);
    
    
    
    //2.计算名字的frame
    CGFloat userNameX = CGRectGetMaxX(_userImageFrame) + kMargin;
    
    CGFloat userNameY = kMargin;
    
    CGSize nameMaxSize = CGSizeMake(MAXFLOAT, 20);
    
    NSDictionary *nameAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    //计算name LabelSize
    CGSize userNameSize  = [StatuesModel.user.name boundingRectWithSize:nameMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nameAttributes context:nil].size;
    
    _userNmaeFrame = CGRectMake(userNameX, userNameY, userNameSize.width, userNameSize.height);
    
    //3.计算时间label的frame;
    CGFloat timeX = CGRectGetMaxX(_userImageFrame) + kMargin;
    CGFloat timeY = CGRectGetMaxY(_userNmaeFrame) + kMargin*0.5 ;
    
//    CGSize timeMaxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 15);
//    NSDictionary *timeAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
//
//    CGSize timeSize = [StatuesModel.created_at boundingRectWithSize:timeMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:timeAttributes context:nil].size;
    
    _timeFrame = CGRectMake(timeX, timeY, 70, 15);
    
    //4.计算内容的frame;
    CGFloat contentX = kMargin;
    CGFloat contentY = CGRectGetMaxY(_userImageFrame)+kMargin;
    NSDictionary *contentAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    CGSize contentMaxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 2*kMargin, MAXFLOAT);
    
    CGSize contentSize = [StatuesModel.text boundingRectWithSize:contentMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:contentAttributes context:nil].size;
    
    _contentFrame = CGRectMake(contentX, contentY, contentSize.width, contentSize.height );
    
    _cellHeight = CGRectGetMaxY(_contentFrame) + kMargin;
    
}


@end
